﻿using System;
using System.IO;
using System.Xml;
using System.Data;
using System.Text;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Collections.Generic;
using WMSABL;
using WMSABL.SY;
using WMSABL.Warehouse;
using WMSAML.Warehouse;
using ElectronicWMSA.Comm.ClassFiles;
using ElectronicWMSA.Comm.Forms.Message;

namespace ElectronicWMSA.Warehouse
{
    public partial class Warehouse_OrderPickingRouteFrm : Form
    {
        #region
        private int PD_LayoutNID = 0;//
        private int SelectRowIndex = -1;
        private int SelectColumnsIndex = -1;
        private string StartpointRows = "";
        private string StartpointColumns = "";
        private string strWhere = "";
        private string PD_LayoutField = "";
        private string Area = "";
        private string Postion = "";
        PD_LayoutUpdateBLL bll = new PD_LayoutUpdateBLL();
        PublicDataSet bll_PublicDataSet = new PublicDataSet();
        PublicDataSet_SAP bll_PublicDataSet_SAP = new PublicDataSet_SAP();
        PD_PickingListBLL bll_PD_PickingList = new PD_PickingListBLL();
        private bool IsLocationPostiont = false;
        DataSet ds = new DataSet();
        private int SH = 0;
        private int SW = 0;
        public Warehouse_OrderPickingRouteFrm()
        {
            InitializeComponent();

            #region
            this.dataGridView1.AllowUserToResizeColumns = false;
            this.dataGridView1.AllowUserToResizeRows = false;
            int H1 = 0;
            int H2 = 0;
            if (File.Exists("SytemConfig.xml"))
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load("SytemConfig.xml");
                foreach (XmlNode item in xmldoc.GetElementsByTagName("DOC"))
                {
                    foreach (XmlNode items in item.ChildNodes)
                    {
                        if (items.Name == "H1")
                            H1 = Convert.ToInt32(items.InnerText.Trim());
                        else if (items.Name == "H2")
                            H2 = Convert.ToInt32(items.InnerText.Trim());
                        else if (items.Name == "StartpointRows")
                            StartpointRows = items.InnerText.Trim();
                        else if (items.Name == "StartpointColumns")
                            StartpointColumns = items.InnerText.Trim();
                    }
                }
            }
            SelectRowIndex = Convert.ToInt32(StartpointRows);
            SelectColumnsIndex = Convert.ToInt32(StartpointColumns);

            SH = Screen.PrimaryScreen.Bounds.Height;
            SW = Screen.PrimaryScreen.Bounds.Width;
            if (SH == 768 && SW == 1366)
                dataGridView1.RowTemplate.Height = H1;
            else if (SH == 1080 && SW == 1920)
                dataGridView1.RowTemplate.Height = H2;
            else if (SH == 1050 && SW == 1680)
                dataGridView1.RowTemplate.Height = H2;
            else if (SH > 1050)
                dataGridView1.RowTemplate.Height = H2;
            else if (SH == 768 && SW == 1024)
                dataGridView1.RowTemplate.Height = H1;
            else
                dataGridView1.RowTemplate.Height = H1;

            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.  
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
            #endregion
        }
        #endregion
        Point Map_StartPoint_UP = new Point();
        #region Load
        Rectangle rec1;
        /// <summary>
        /// 起点坐标
        /// </summary>
        Point Map_StartPoint = new Point(0, 0);
        private void OrderPickingRouteFrm_Load(object sender, EventArgs e)
        {
            this.strWhere = "";
            this.pageControl1.PageCurrent = 1;
            this.pageControl1.PageSize = 500;
            this.pageControl1.Bind();
            this.dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;

            this.dataGridView1.Rows[Convert.ToInt32(StartpointRows)].Cells[Convert.ToInt32(StartpointColumns)].Value = "★";
            this.dataGridView1.Rows[Convert.ToInt32(StartpointRows)].Cells[Convert.ToInt32(StartpointColumns)].Style.BackColor = System.Drawing.Color.Blue;
            this.dataGridView1.Rows[Convert.ToInt32(StartpointRows)].Cells[Convert.ToInt32(StartpointColumns)].Style.Font = new Font("微软雅黑", 8, FontStyle.Regular);

            this.rec1 = this.dataGridView1.GetCellDisplayRectangle(Convert.ToInt32(StartpointColumns), Convert.ToInt32(StartpointRows), false);
            this.Map_StartPoint = new Point(rec1.X + rec1.Width / 2, rec1.Y + rec1.Height / 2);
            Map_StartPoint_UP = Map_StartPoint;
            this.txtPickNo.Focus();
            this.comBoxName.Text = "";
        }

        private int DBind()
        {
            ElectronicWMSA.Comm.Forms.MsControls.PageData pageData = new ElectronicWMSA.Comm.Forms.MsControls.PageData();
            pageData.TableName = "PD_Layout";
            pageData.PrimaryKey = "NID";
            pageData.OrderStr = "NID";
            pageData.PageIndex = this.pageControl1.PageCurrent;
            pageData.PageSize = this.pageControl1.PageSize;
            pageData.QueryCondition = strWhere;
            pageData.QueryFieldName = "*";
            pageControl1.bindingSource.DataSource = pageData.QueryDataTable().Tables[0];
            pageControl1.bindingNavigator.BindingSource = pageControl1.bindingSource;
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = this.pageControl1.bindingSource;

            SystemVariable.DataGridViewStyle(dataGridView1);
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (i != 0 && i != dataGridView1.RowCount - 1)
                {
                    for (int j = 0; j < dataGridView1.ColumnCount; j++)
                    {
                        if (this.dataGridView1.Rows[i].Cells[j].FormattedValue.ToString() == "")
                        {
                            this.dataGridView1.Rows[i].Cells[j].Style.BackColor = Color_value;
                        }
                    }
                }
            }

            DataTable dtdddd = dataVoid();
            #region
            //for (int i = 0; i < dataGridView1.Rows.Count; i++)
            //{
            //    if (i != 0 && i != dataGridView1.RowCount - 1)
            //    {
            //        for (int j = 0; j < dataGridView1.ColumnCount; j++)
            //        {
            //            if (this.dataGridView1.Rows[i].Cells[j].FormattedValue.ToString() == "N13-3-1" || this.dataGridView1.Rows[i].Cells[j].FormattedValue.ToString() == "N13-3-2")
            //            {
            //                this.dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.Blue;
            //            }
            //            if (this.dataGridView1.Rows[i].Cells[j].FormattedValue.ToString() == "N13-2-1" || this.dataGridView1.Rows[i].Cells[j].FormattedValue.ToString() == "N13-2-2")
            //            {
            //                this.dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.Blue;
            //            }
            //            if (this.dataGridView1.Rows[i].Cells[j].FormattedValue.ToString() == "N13-1-1" || this.dataGridView1.Rows[i].Cells[j].FormattedValue.ToString() == "N13-1-2")
            //            {
            //                this.dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.Blue;
            //            }
            //            //if (dtdddd.Select(" PositionNO='"+this.dataGridView1.Rows[i].Cells[j].FormattedValue.ToString()+"'").Length<0)
            //            //{
            //            //    this.dataGridView1.Rows[i].Cells[j].Style.BackColor = Color.Yellow;
            //            //}
            //        }
            //    }
            //}

            //for (int i = 0; i < dataGridView1.Rows.Count; i++)
            //{
            //    if (i != dataGridView1.RowCount - 1 && i > 9)
            //    {
            //        this.dataGridView1.Rows[i].Cells[20].Style.BackColor = Color_value;
            //        this.dataGridView1.Rows[i].Cells[26].Style.BackColor = Color_value;
            //        this.dataGridView1.Rows[i].Cells[35].Style.BackColor = Color_value;
            //        this.dataGridView1.Rows[i].Cells[43].Style.BackColor = Color_value;
            //        this.dataGridView1.Rows[i].Cells[52].Style.BackColor = Color_value;
            //        this.dataGridView1.Rows[i].Cells[57].Style.BackColor = Color_value;
            //    }
            //}

            //for (int i = 0; i < dataGridView1.Rows.Count; i++)
            //{
            //    if (dataGridView1.Rows[i].Cells["txt"].Value.ToString() == "10")
            //    {
            //        dataGridView1.Rows[i].Height = 7;
            //        dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color_value;
            //    }
            //    else if (dataGridView1.Rows[i].Cells["txt"].Value.ToString() == "宽")
            //    {
            //        dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color_value;
            //    }
            //}

            #endregion

            //for (int i = 0; i < dataGridView1.Rows.Count; i++)
            //{
            //    if (dataGridView1.Rows[i].Cells["txt"].Value.ToString() == "10")
            //    {
            //        dataGridView1.Rows[i].Height = 7;
            //    }
            //}

            //if (checkBoxLineShow.Checked)
            //    dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
            //else
            dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;

            if (SH > 768 && SW > 1366)
            {
                dataGridView1.RowsDefaultCellStyle.Font = new Font("微软雅黑", 6, FontStyle.Regular);
                dataGridView1.Rows[0].DefaultCellStyle.Font = new Font("微软雅黑", 10, FontStyle.Regular);
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].DefaultCellStyle.Font = new Font("微软雅黑", 10, FontStyle.Regular);
            }
            else
            {
                dataGridView1.RowsDefaultCellStyle.Font = new Font("微软雅黑", 4, FontStyle.Regular);
                dataGridView1.Rows[0].DefaultCellStyle.Font = new Font("微软雅黑", 6, FontStyle.Regular);
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].DefaultCellStyle.Font = new Font("微软雅黑", 6, FontStyle.Regular);
            }

            dataGridView1.Rows[0].DefaultCellStyle.BackColor = System.Drawing.Color.MediumSeaGreen;
            dataGridView1.Rows[dataGridView1.RowCount - 1].DefaultCellStyle.BackColor = System.Drawing.Color.MediumSeaGreen;

            return pageData.TotalCount;
        }
        private DataTable dataVoid()
        {
            DataTable dt = bll_PublicDataSet.GetDataSet("  SELECT [PositionNO]  FROM [dbo].[PD_PostionToLayout] ").Tables[0];
            return dt;
        }
        private int pageControlU_EventPaging(ElectronicWMSA.Comm.Forms.MsControls.EventPagingArg e)
        {
            return DBind();
        }
        #endregion

        #region 事件
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1 && e.ColumnIndex != -1 && SelectRowIndex > -1)
            {
                this.dataGridView1.Rows[SelectRowIndex].DefaultCellStyle.BackColor = System.Drawing.Color.Gainsboro;
                ds = new DataSet();
                ds = bll_PublicDataSet.GetDataSet("SELECT a.Posiont1 ,Product_Model FROM T_Stock AS a LEFT JOIN PD_PostionToLayout AS b ON b.PositionNO=a.Posiont1 WHERE b.Layout_NID='" + PD_LayoutNID + "' AND b.Layout_Field='" + PD_LayoutField + "' AND PickList_NO is null AND a.BK06!='0' ");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    Postion_LayoutDataFrm frm = new Postion_LayoutDataFrm(ds);
                    frm.ShowDialog();
                    this.dataGridView1.ClearSelection();
                }
                else
                {
                    MessageClass.warning("此区域无信息！");
                }
            }
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            SelectRowIndex = -1;
            if (e.RowIndex > -1 && e.ColumnIndex > 1)
            {
                SelectRowIndex = e.RowIndex;
                PD_LayoutNID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["NID"].Value);
                PD_LayoutField = dataGridView1.Columns[e.ColumnIndex].HeaderText.ToString();
                if (dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[e.ColumnIndex].Value != null)
                {
                    Area = dataGridView1.Rows[dataGridView1.RowCount - 1].Cells[e.ColumnIndex].Value.ToString();
                    Postion = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                }
            }
        }

        #endregion

        #region 重新定位起点
        private void btnGOSet_Click(object sender, EventArgs e)
        {
            if (Postion != "")
            {
                MessageClass.warning("此位置不能设置为起点，请选择无信息的区域！");
                return;
            }
            this.checkBox1.Checked = false;
            this.PickMapTimer.Enabled = false;
            this.timerUserName.Enabled = false;
            this.indexPickNo = 0;

            if (SelectRowIndex > 1 && SelectColumnsIndex > 1)
            {
                if (MessageClass.enquire("确认重新设置拣货起点？") == DialogResult.OK)
                {
                    dataGridView1.Rows[Convert.ToInt32(StartpointRows)].Cells[Convert.ToInt32(StartpointColumns)].Value = "";
                    dataGridView1.Rows[Convert.ToInt32(StartpointRows)].Cells[Convert.ToInt32(StartpointColumns)].Style.BackColor = System.Drawing.Color.Transparent;

                    rec1 = this.dataGridView1.GetCellDisplayRectangle(SelectColumnsIndex, SelectRowIndex, false);
                    Map_StartPoint = new Point(rec1.X + rec1.Width / 2, rec1.Y + rec1.Height / 2);

                    dataGridView1.Rows[SelectRowIndex].Cells[SelectColumnsIndex].Value = "★";
                    dataGridView1.Rows[SelectRowIndex].Cells[SelectColumnsIndex].Style.BackColor = System.Drawing.Color.Blue;
                    dataGridView1.Rows[SelectRowIndex].Cells[SelectColumnsIndex].Style.Font = new Font("微软雅黑", 8, FontStyle.Regular);

                    StartpointRows = SelectRowIndex.ToString();
                    StartpointColumns = SelectColumnsIndex.ToString();
                    XmlDocument doc = new XmlDocument();
                    string strFileName = Application.StartupPath + "\\SytemConfig.xml";
                    doc.Load(strFileName);
                    XmlNodeList nodeList = doc.SelectSingleNode("DOC").ChildNodes;
                    foreach (XmlNode xn in nodeList)
                    {
                        if (xn.Name == "StartpointRows")
                            xn.InnerText = SelectRowIndex.ToString();
                        else if (xn.Name == "StartpointColumns")
                            xn.InnerText = SelectColumnsIndex.ToString();
                    }
                    doc.Save(strFileName);
                }
            }
            else
            {
                MessageClass.warning("选择起点位置！");
            }
        }
        #endregion

        #region  查询定位
        private void btnSearch_Click(object sender, EventArgs e)
        {
            this.pageControl1.Bind();
            this.LocationPostiont();
        }

        private Rectangle rec;
        private string Point01;
        private string Point02;
        private string Point03;
        private string Point04;
        private string Point05;

        private int IndexRows = 0;//空行
        private int IndexRight = 0;//空列右
        private int IndexCenter = 0;//空列中
        private int IndexLeft = 0;//空列左

        private int IndexTop = 0;//空列上
        private int IndexDown = 0;//空列下

        private int IndexRowsTop = 0;
        private int IndexRowsDown = 0;


        string files1 = "";
        string files2 = "";
        private void LocationPostiont()
        {
            try
            {
                #region
                files1 = "";
                files2 = "";
                ds = new DataSet();
                if (txtPickNo.Text.Trim() == "")
                {
                    MessageClass.warning("拣货单号不能为空！");
                    this.pageControl1.Bind();
                }
                else if (this.txtPickNo.Text.Trim() != "")
                {

                    ds = new DataSet();
                    ds = bll_PublicDataSet.GetDataSet("select COUNT(PackingListDetails_Id) from T_PackingListDetails  where packinglistmain_no='" + txtPickNo.Text.Trim() + "' and ProDate>='" + DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd") + "' and ProDate<='" + DateTime.Now.AddDays(2).ToString("yyyy-MM-dd") + "'");//SELECT COUNT(NID) FROM PD_PickingList WHERE PickNO='" + txtPickNo.Text.Trim() + "' ");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        ds = new DataSet();
                        StringBuilder sb = new StringBuilder();
                        sb.Append(" SELECT distinct A.NID,A.Layout_NID,A.Layout_Field,A.pointTop,A.pointL ,A.pointR,PointU,PointD,C.Status from PD_PostionToLayout AS A  ");
                        sb.Append(" LEFT JOIN T_Stock AS B ON A.PositionNO=B.Posiont1 ");
                        sb.Append(" LEFT JOIN T_PackingListDetails  AS C ON c.Customer=b.Product_Model  ");
                        sb.Append(" WHERE C.packinglistmain_no='" + this.txtPickNo.Text.Trim() + "'  and A.Stauts=0  ORDER BY Layout_Field ASC ");

                        ds = bll_PublicDataSet.GetDataSet(sb.ToString());
                        int updateNID = 0;
                        string strField = "";
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            #region
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                #region
                                for (int j = 0; j < dataGridView1.RowCount; j++)
                                {
                                    if (dataGridView1.Rows[j].Cells["NID"].Value.ToString() == ds.Tables[0].Rows[i]["Layout_NID"].ToString())
                                    {
                                        for (int y = 0; y < dataGridView1.ColumnCount; y++)
                                        {
                                            IndexRows = 0;
                                            IndexRight = 0;
                                            IndexCenter = 0;
                                            IndexLeft = 0;
                                            IndexTop = 0;
                                            IndexDown = 0;
                                            IndexLeft = 0;
                                            strField = ds.Tables[0].Rows[i]["Layout_Field"].ToString();
                                            if (dataGridView1.Columns[y].HeaderText == strField)
                                            {
                                                updateNID = Convert.ToInt32(ds.Tables[0].Rows[i]["NID"].ToString());
                                                if (ds.Tables[0].Rows[i]["Status"].ToString() == "" || ds.Tables[0].Rows[i]["Status"].ToString() == "1")
                                                {
                                                    dataGridView1.Rows[j].Cells[y].Style.BackColor = System.Drawing.Color.Red;
                                                }
                                                else if (ds.Tables[0].Rows[i]["Status"].ToString() == "2")
                                                {
                                                    dataGridView1.Rows[j].Cells[y].Style.BackColor = System.Drawing.Color.DodgerBlue;
                                                }
                                                else
                                                {
                                                    dataGridView1.Rows[j].Cells[y].Style.BackColor = System.Drawing.Color.Red;
                                                }

                                                #region 更改坐标值     ////////////  ////////////  ////////////  ////////////  ////////////  ////////////  ////////////  ////////////  ////////////  ////////////  ////////////  ////////////  ////////////  ////////////  ////////////  ////////////


                                                //// 取上下
                                                for (int xx = j; xx < dataGridView1.RowCount; xx--)
                                                {
                                                    if (dataGridView1.Rows[xx].Cells[y].Value == null || dataGridView1.Rows[xx].Cells[y].Value.ToString() == "")
                                                    {
                                                        IndexTop = y;
                                                        IndexRowsTop = xx;
                                                        break;
                                                    }
                                                }
                                                IndexCenter = j;
                                                for (int xx = j; xx < dataGridView1.RowCount; xx++)
                                                {
                                                    if (dataGridView1.Rows[xx].Cells[y].Value == null || dataGridView1.Rows[xx].Cells[y].Value.ToString() == "")
                                                    {
                                                        IndexDown = y;
                                                        IndexRowsDown = xx;
                                                        break;
                                                    }
                                                }

                                                //取左右 
                                                for (int h = y; h < dataGridView1.ColumnCount; h++)
                                                {
                                                    if (dataGridView1.Rows[j].Cells[h].Value == null || dataGridView1.Rows[j].Cells[h].Value.ToString() == "")
                                                    {
                                                        IndexRight = h;
                                                        break;
                                                    }
                                                }
                                                for (int h = y; h > -1; h--)
                                                {
                                                    if (dataGridView1.Rows[j].Cells[h].Value == null || dataGridView1.Rows[j].Cells[h].Value.ToString() == "")
                                                    {
                                                        IndexLeft = h;
                                                        break;
                                                    }
                                                }

                                                rec = this.dataGridView1.GetCellDisplayRectangle(IndexLeft, IndexCenter, false);//左
                                                Point01 = (rec.X + rec.Width / 2) + "," + (rec.Y + rec.Height / 2);

                                                rec = this.dataGridView1.GetCellDisplayRectangle(IndexTop, IndexRowsTop, false);//上
                                                Point02 = (rec.X + rec.Width / 2) + "," + (rec.Y + rec.Height / 2);

                                                rec = this.dataGridView1.GetCellDisplayRectangle(y, j, false);//原
                                                Point03 = (rec.X + rec.Width / 2) + "," + (rec.Y + rec.Height / 2);

                                                rec = this.dataGridView1.GetCellDisplayRectangle(IndexDown, IndexRowsDown, false);//下
                                                Point04 = (rec.X + rec.Width / 2) + "," + (rec.Y + rec.Height / 2);

                                                rec = this.dataGridView1.GetCellDisplayRectangle(IndexRight, IndexCenter, false);//右
                                                Point05 = (rec.X + rec.Width / 2) + "," + (rec.Y + rec.Height / 2);

                                                bll_PublicDataSet.ExecuteSQL("UPDATE PD_PostionToLayout SET PointTop='" + Point01 + "', PointL='" + Point02 + "', PointR='" + Point03 + "',PointU='" + Point04 + "',PointD='" + Point05 + "',field1='" + IndexRows + "," + IndexCenter + "' WHERE NID='" + updateNID + "'   ");
                                                #endregion
                                                break;
                                            }
                                        }
                                        break;
                                    }

                                }
                                #endregion
                            }

                            if (files2 != "")
                            {
                                string[] var = files2.Split(',');
                                this.dataGridView1.Rows[Convert.ToInt32(var[0])].Cells[Convert.ToInt32(var[1])].Value = "★";
                                this.dataGridView1.Rows[Convert.ToInt32(var[0])].Cells[Convert.ToInt32(var[1])].Style.BackColor = System.Drawing.Color.Blue;
                                this.dataGridView1.Rows[Convert.ToInt32(var[0])].Cells[Convert.ToInt32(var[1])].Style.Font = new Font("微软雅黑", 4, FontStyle.Regular);
                            }
                            this.dataGridView1.Rows[Convert.ToInt32(StartpointRows)].Cells[Convert.ToInt32(StartpointColumns)].Value = "★";
                            this.dataGridView1.Rows[Convert.ToInt32(StartpointRows)].Cells[Convert.ToInt32(StartpointColumns)].Style.BackColor = System.Drawing.Color.Blue;
                            this.dataGridView1.Rows[Convert.ToInt32(StartpointRows)].Cells[Convert.ToInt32(StartpointColumns)].Style.Font = new Font("微软雅黑", 8, FontStyle.Regular);
                            this.IsLocationPostiont = true;
                            this.labelMessage.Visible = false;
                            #endregion
                        }
                        else
                        {
                            this.labelMessage.Visible = true;
                            this.labelMessage.Text = "未检测配料员：【" + this.comBoxName.Text.Trim() + "】的对应信息！";
                            IsLocationPostiont = false;
                            this.pageControl1.Bind();
                        }
                    }
                    else
                    {
                        this.labelMessage.Visible = true;
                        this.labelMessage.Text = "无拣货单信息，请核查！";
                        IsLocationPostiont = false;
                        this.pageControl1.Bind();
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                ErrorLogLoad.ErrorLogInfo(ex.ToString());
            }
        }
        #region
        public void DBindCombox()
        {
            DataSet ds = new DataSet();
            ds = bll_PublicDataSet.GetDataSet(" SELECT '1' AS NID,UserCode FROM dbo.PD_PickingList WHERE PickNO='" + this.txtPickNo.Text.Trim() + "' GROUP BY UserCode ");
            this.comBoxName.DataSource = ds.Tables[0];
            this.comBoxName.ValueMember = "NID";
            this.comBoxName.DisplayMember = "UserCode";
        }
        #endregion

        private void btnClear_Click(object sender, EventArgs e)
        {
            this.txtPickNo.Text = "";
            this.IsLocationPostiont = false;
            this.pageControl1.Bind();
        }
        #endregion

        #region 取货线路显示
        #region
        DataTable DataTable1 = new DataTable();
        DataTable DataTable2 = new DataTable();
        DataTable DataTable3 = new DataTable();
        public void CreaterdataTable()
        {
            DataTable1 = new DataTable();
            DataTable1.Columns.Add("Range");
            DataTable1.Columns.Add("Point");
            DataTable1.Columns.Add("pointTop");
            DataTable1.Columns.Add("pointL");
            DataTable1.Columns.Add("pointR");
            DataTable1.Columns.Add("PointU");
            DataTable1.Columns.Add("PointD");
            DataTable1.Columns.Add("PositionNO");


            DataTable2 = new DataTable();
            DataTable2.Columns.Add("Layout_Field");
            DataTable2.Columns.Add("pointTop");
            DataTable2.Columns.Add("pointL");
            DataTable2.Columns.Add("pointR");
            DataTable2.Columns.Add("PointU");
            DataTable2.Columns.Add("PointD");
            DataTable2.Columns.Add("PositionNO");

            DataTable3 = new DataTable();
            DataTable3.Columns.Add("Layout_Field");
            DataTable3.Columns.Add("pointTop");
            DataTable3.Columns.Add("pointL");
            DataTable3.Columns.Add("pointR");
            DataTable3.Columns.Add("PointU");
            DataTable3.Columns.Add("PointD");
            DataTable3.Columns.Add("PositionNO");
        }
        #endregion
        private void btnLine_Click(object sender, EventArgs e)
        {
            if (IsLocationPostiont)
            {
                string[] valuesstr = null;
                int PDRightLeft = 0;
                Point Posiont_Center = new Point();
                Point Posiont_Start = new Point();
                Point Posiont_0L = new Point();
                Point Posiont_0R = new Point();
                Posiont_Start = Map_StartPoint_UP;// 每次替换
                double LegthMin = 0;// 存长度
                double GetLegth = 0;// 获取两点长度
                int index_Tb2 = -1;
                CreaterdataTable();
                ds = new DataSet();
                StringBuilder sb = new StringBuilder();
                sb.Append(" SELECT distinct A.NID,A.Layout_NID,A.Layout_Field,A.pointTop,A.pointL ,A.pointR,PointU,PointD,C.Status,A.PositionNO from PD_PostionToLayout AS A  ");
                sb.Append(" LEFT JOIN T_Stock AS B ON A.PositionNO=B.Posiont1 ");
                sb.Append(" LEFT JOIN T_PackingListDetails  AS C ON c.Customer=b.Product_Model  ");

                sb.Append(" WHERE C.packinglistmain_no='" + this.txtPickNo.Text.Trim() + "'  and A.Stauts=0   order by  A.PositionNO DESC ");
                ds = bll_PublicDataSet.GetDataSet(sb.ToString());

                #region
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {

                    string[] valuesstr1 = ds.Tables[0].Rows[i]["PointR"].ToString().Split(',');
                    Point Posiont_0 = new Point();
                    Posiont_0 = new Point(Convert.ToInt32(valuesstr1[0]), Convert.ToInt32(valuesstr1[1]));

                    DataRow dr = DataTable1.NewRow();
                    dr["Range"] = GetDoublePoint_Value(Posiont_00, Posiont_0);
                    dr["Point"] = ds.Tables[0].Rows[i]["PointR"].ToString();
                    dr["PositionNO"] = ds.Tables[0].Rows[i]["PositionNO"].ToString();
                    dr["pointTop"] = ds.Tables[0].Rows[i]["pointTop"].ToString();
                    dr["pointL"] = ds.Tables[0].Rows[i]["pointL"].ToString();
                    dr["pointR"] = ds.Tables[0].Rows[i]["pointR"].ToString();
                    dr["PointU"] = ds.Tables[0].Rows[i]["PointU"].ToString();
                    dr["PointD"] = ds.Tables[0].Rows[i]["PointD"].ToString();
                    DataTable1.Rows.Add(dr);

                }
                DataTable1.DefaultView.Sort = " Range  ASC";
                DataTable1 = DataTable1.DefaultView.ToTable();


                #endregion
                WaitingBoxFrm wf = new WaitingBoxFrm((obj, args) => { Thread.Sleep(1000); DrawLines(); }, 30); wf.ShowDialog(this);

                Pen blackPen = new Pen(Color.DodgerBlue, 2);
                this.dataGridView1.CreateGraphics().DrawLines(blackPen, Posiont_listPoint.ToArray());


                labelInfo.Text = "当前拣货单号:【" + this.txtPickNo.Text.Trim() + "】,【" + this.comBoxName.Text.Trim() + "】";
            }
            else
            {
                MessageClass.warning("请对拣货单定位！");
            }
        }
        /// <summary>
        /// 获取位置坐标集合
        /// </summary>
        List<Point> Posiont_listPoint = new List<Point>();
        /// <summary>
        /// 原点
        /// </summary>
        Point Posiont_01 = new Point();
        /// <summary>
        /// 仓位点
        /// </summary>
        Point Posiont_02 = new Point();
        /// <summary>
        /// 距离原点最近的第一点
        /// </summary>
        Point Posiont_03 = new Point();
        /// <summary>
        /// 距离原点最近的第二点
        /// </summary>
        Point Posiont_04 = new Point();
        /// <summary>
        /// 进入仓库返回点
        /// </summary>
        Point Posiont_05 = new Point();
        List<double> listRange = new List<double>();
        private void DrawLines()
        {
            Posiont_00 = Map_StartPoint;
            this.Posiont_listPoint.Clear();


            DataRow[] rows = DataTable1.Select("", "Range  asc");

            DataTable1 = ToDataTable(rows); 


               // Posiont_listPoint.Add(Posiont_00);
               Posiont_00 = Map_StartPoint;
            for (int i = 0; i < DataTable1.Rows.Count; i++)
            {

                for (int j = 0; j < dataGridView1.RowCount; j++)
                {

                    for (int y = 0; y < dataGridView1.ColumnCount; y++)
                    {
                        string nuame = dataGridView1.Rows[j].Cells[y].FormattedValue.ToString();
                        if (nuame.Trim().ToUpper() == DataTable1.Rows[i]["PositionNO"].ToString().Trim().ToUpper())
                        {

                            string pd = dataGridView1.Rows[0].Cells[y].FormattedValue.ToString();
                            if (pd == "L")
                            {
                                Posiont_01 = Posiont_00;

                                string[] valuesstr1 = DataTable1.Rows[i]["pointR"].ToString().Split(',');
                                Posiont_02 = new Point(Convert.ToInt32(valuesstr1[0]), Convert.ToInt32(valuesstr1[1]));

                                string[] valuesstr2 = DataTable1.Rows[i]["PointD"].ToString().Split(',');
                                Posiont_04 = new Point(Convert.ToInt32(valuesstr2[0]), Convert.ToInt32(valuesstr2[1]));

                                Posiont_03 = new Point(Posiont_04.X, Posiont_01.Y);
                                Posiont_05 = Posiont_02;

                                //没有交叉轴的计算
                                if (Posiont_02.X > 184)
                                {
                                    string[] valuesstr3 = DataTable1.Rows[i]["PointU"].ToString().Split(',');
                                    Point Posiont6 = new Point(Convert.ToInt32(valuesstr3[0]), Convert.ToInt32(valuesstr3[1]));
                                    Posiont_03 = new Point(Posiont_01.X, Posiont6.Y);
                                    Posiont_05 = new Point(Posiont_04.X, Posiont_03.Y);

                                    Posiont_listPoint.Add(Posiont_01);
                                    Posiont_listPoint.Add(Posiont_03);
                                    Posiont_listPoint.Add(Posiont_05);
                                    Posiont_listPoint.Add(Posiont_04);
                                    Posiont_listPoint.Add(Posiont_02);
                                    Posiont_00 = Posiont_04;
                                }
                                else
                                {
                                    Posiont_listPoint.Add(Posiont_01);
                                    Posiont_listPoint.Add(Posiont_03);
                                    Posiont_listPoint.Add(Posiont_04);
                                    Posiont_listPoint.Add(Posiont_02);
                                    Posiont_listPoint.Add(Posiont_05);
                                    Posiont_00 = Posiont_04;
                                }

                                va(Posiont_01, Posiont_02, Posiont_03, Posiont_04, Posiont_05);
                            }
                            else
                            {
                                Posiont_01 = Posiont_00;

                                string[] valuesstr1 = DataTable1.Rows[i]["pointR"].ToString().Split(',');
                                Posiont_02 = new Point(Convert.ToInt32(valuesstr1[0]), Convert.ToInt32(valuesstr1[1]));

                                string[] valuesstr2 = DataTable1.Rows[i]["pointTop"].ToString().Split(',');
                                Posiont_04 = new Point(Convert.ToInt32(valuesstr2[0]), Convert.ToInt32(valuesstr2[1]));

                                string[] valuesstr3 = DataTable1.Rows[i]["PointU"].ToString().Split(',');
                                Point Posiont6 = new Point(Convert.ToInt32(valuesstr3[0]), Convert.ToInt32(valuesstr3[1]));
                                Posiont_03 = new Point(Posiont_01.X, Posiont6.Y);
                                Posiont_05 = new Point(Posiont_04.X, Posiont_03.Y);

                                Posiont_listPoint.Add(Posiont_01);
                                Posiont_listPoint.Add(Posiont_03);
                                Posiont_listPoint.Add(Posiont_05);
                                Posiont_listPoint.Add(Posiont_04);
                                Posiont_listPoint.Add(Posiont_02);
                                Posiont_00 = Posiont_04;

                          


                                va(Posiont_01, Posiont_02, Posiont_03, Posiont_04, Posiont_05);
                            }
                            break;
                        }
                    }

                }


                //valuesstr = ds.Tables[0].Rows[i]["PointTop"].ToString().Split(',');
                //Posiont_01 = new Point(Convert.ToInt32(valuesstr[0]), Convert.ToInt32(valuesstr[1]));

                //valuesstr = ds.Tables[0].Rows[i]["PointL"].ToString().Split(',');
                //Posiont_02 = new Point(Convert.ToInt32(valuesstr[0]), Convert.ToInt32(valuesstr[1]));

                //valuesstr = ds.Tables[0].Rows[i]["PointR"].ToString().Split(',');
                //Posiont_03 = new Point(Convert.ToInt32(valuesstr[0]), Convert.ToInt32(valuesstr[1]));

                //valuesstr = ds.Tables[0].Rows[i]["PointU"].ToString().Split(',');
                //Posiont_04 = new Point(Convert.ToInt32(valuesstr[0]), Convert.ToInt32(valuesstr[1]));

                //valuesstr = ds.Tables[0].Rows[i]["PointD"].ToString().Split(',');
                //Posiont_05 = new Point(Convert.ToInt32(valuesstr[0]), Convert.ToInt32(valuesstr[1]));

                //va(Posiont_01, Posiont_02, Posiont_03, Posiont_04, Posiont_05);
            }
        }

        /// <summary>
        /// 起点斜街坐标
        /// </summary>
        Point Posiont_00 = new Point();
        Point Posiont_91 = new Point(0, 0);
        Point Posiont_92 = new Point(0, 0);
        private void va(Point Point1, Point Point2, Point Point3, Point Point4, Point Point5)
        {

            //if (Posiont_01.X != Posiont_03.X || Posiont_01.Y != Posiont_03.Y)
            //{
            //    Posiont_listPoint.Add(Point1);
            //    Posiont_listPoint.Add(Point3);
            //    Posiont_listPoint.Add(Point4);
            //    Posiont_listPoint.Add(Point2);
            //    Posiont_listPoint.Add(Point5);
            //}
            //Posiont_00 = Point5;
            //double length1 = 0;
            //double length2 = 0;
            //Posiont_91 = new Point(0, 0);
            //Posiont_92 = new Point(0, 0);


            //if (Posiont_00.X != Point2.X)
            //{
            //    Posiont_91 = new Point(Point1.X, Posiont_00.Y);
            //    length1 = GetDoublePoint_Value(Posiont_00, Point1) + GetDoublePoint_Value(Point1, Point2) + GetDoublePoint_Value(Point2, Point3);
            //}
            //else
            //{
            //  length1 = GetDoublePoint_Value(Point1, Point3) + GetDoublePoint_Value(Point1, Point4) + GetDoublePoint_Value(Point1, Point2);
            //}

            //if (Posiont_00.X != Point5.X)
            //{
            //    Posiont_92 = new Point(Point5.X, Posiont_00.Y);
            //    length2 = GetDoublePoint_Value(Posiont_00, Point5) + GetDoublePoint_Value(Point5, Point4) + GetDoublePoint_Value(Point4, Point3);
            //}
            //else
            //{
            //    length2 = GetDoublePoint_Value(Posiont_00, Point5) + GetDoublePoint_Value(Point5, Point4) + GetDoublePoint_Value(Point4, Point3);
            //}

            //if (length1 < length2 || length1 == length2)
            //{
            //    if (Posiont_91.X != 0)
            //        Posiont_listPoint.Add(Posiont_91);
            //    Posiont_listPoint.Add(Point1);
            //    Posiont_listPoint.Add(Point2);
            //    Posiont_listPoint.Add(Point3);
            //    Posiont_listPoint.Add(Point4);
            //    Posiont_listPoint.Add(Point5);
            //    Posiont_00 = Point1;
            //}
            //else
            //{
            //    if (Posiont_92.X != 0)
            //        Posiont_listPoint.Add(Posiont_92);
            //    Posiont_listPoint.Add(Point1);
            //    Posiont_listPoint.Add(Point2);
            //    Posiont_listPoint.Add(Point3);
            //    Posiont_listPoint.Add(Point4);
            //    Posiont_listPoint.Add(Point5);
            //    Posiont_00 = Point5;
            //}
        }

        /// <summary>
        /// 两坐标之间距离
        /// </summary>
        private double GetDoublePoint_Value(Point p1, Point p2)
        {
            return Math.Round(Math.Sqrt(Math.Abs(p1.X - p2.X) * Math.Abs(p1.X - p2.X) + Math.Abs(p1.Y - p2.Y) * Math.Abs(p1.Y - p2.Y)), 2);
        }
        /// <summary>
        /// 清除路线图
        /// </summary>
        private void BtnClearLine_Click(object sender, EventArgs e)
        {
            labelInfo.Text = "当前拣货单号/拣货员路线: 无 ";
            this.dataGridView1.Invalidate();
        }
        #endregion
        /// <summary>
        /// 将dataRow转Datatble
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        private DataTable ToDataTable(DataRow[] rows)
        {
            if (rows == null || rows.Length == 0) return null;
            DataTable tmp = rows[0].Table.Clone(); // 复制DataRow的表结构
            foreach (DataRow row in rows)
            {

                tmp.ImportRow(row); // 将DataRow添加到DataTable中
            }
            return tmp;
        }
        #region SAP 拣货单号信息
        private void btnPickingInfo_Click(object sender, EventArgs e)
        {
            this.checkBox1.Checked = false;
            this.PickMapTimer.Enabled = false;
            this.timerUserName.Enabled = false;
            this.indexPickNo = 0;

            if (txtPickNo.Text.Trim() == "")
            {
                MessageClass.warning("拣货单号不能为空！");
            }
            else if (txtPickNo.Text.Trim() != "")
            {
                ds = new DataSet();
                ds = bll_PublicDataSet.GetDataSet("select  packinglistmain_no as 'PickNO',Destination as 'Line' ,Customer as 'ProductNO', TTL_Qty as 'NeedQty' from T_PackingListDetails WHERE packinglistmain_no='" + txtPickNo.Text.Trim() + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ElectronicWMSA.Warehouse.Picking_ListToNumberInfoFrm frm = new ElectronicWMSA.Warehouse.Picking_ListToNumberInfoFrm(ds);
                    frm.ShowDialog();
                    this.dataGridView1.ClearSelection();
                }
                else
                {
                    MessageClass.warning("未能检测到拣货单信息，请进行》拣货单核查！");
                }
            }
        }
        #endregion

        #region 获取拣货员
        private void btnGetUserName_Click(object sender, EventArgs e)
        {
            this.checkBox1.Checked = false;
            this.PickMapTimer.Enabled = false;
            this.timerUserName.Enabled = false;
            this.indexPickNo = 0;

            dsPicking = bll_PublicDataSet.GetDataSet("SELECT packinglistmain_no,pick_UserNO FROM dbo.T_PackingListDetails WHERE [Status] is null  GROUP BY packinglistmain_no,pick_UserNO ");
            ds = new DataSet();
            if (txtPickNo.Text.Trim() == "")
            {
                MessageClass.warning("拣货单号不能为空！");
                this.pageControl1.Bind();
            }
            else if (this.txtPickNo.Text.Trim() != "")
            {
                ds = new DataSet();
                ds = bll_PublicDataSet.GetDataSet("SELECT COUNT(PackingListDetails_Id) FROM dbo.T_PackingListDetails WHERE packinglistmain_no='" + txtPickNo.Text.Trim() + "' ");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DBindCombox();
                }
                else
                {
                    MessageClass.warning("未能检测到拣货单信息，请进行》拣货单核查！");
                }
            }
        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.checkBox1.Checked = false;
            this.PickMapTimer.Enabled = false;
            this.timerUserName.Enabled = false;
            this.indexPickNo = 0;
            this.Close();
            //System.Environment.Exit(0);
        }
        #endregion

        #region 路线匹配自动制图

        #region 制图存储
        PD_PickingMapEntity entity_Map = new PD_PickingMapEntity();
        PD_PickingMap_BLL bll_Map = new PD_PickingMap_BLL();
        private void SaveMap()
        {
            try
            {
                #region SaveMap
                entity_Map = new PD_PickingMapEntity();
                entity_Map = bll_Map.Getentity(pickNO1, userCode1);
                if (entity_Map == null)
                {
                    Bitmap map = new Bitmap(this.Width, this.Height);
                    Rectangle rec = new Rectangle(Point.Empty, dataGridView1.Size);
                    this.dataGridView1.DrawToBitmap(map, rec);
                    Clipboard.SetImage(map);
                    Graphics g = Graphics.FromImage(map);

                    // 设置画布的描绘质量
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.CopyFromScreen(dataGridView1.PointToScreen(this.Location), Point.Empty, dataGridView1.Size);
                    Clipboard.SetImage(map);
                    // 保存图片
                    string nameMap = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString();
                    map.Save(Application.StartupPath + "\\PLD\\" + nameMap + ".png");

                    byte[] bytes1 = null;
                    FileStream fs1 = new FileStream(Application.StartupPath + "\\PLD\\" + nameMap + ".png", FileMode.Open);
                    bytes1 = new byte[fs1.Length];
                    fs1.Read(bytes1, 0, (int)fs1.Length);

                    entity_Map = new PD_PickingMapEntity();
                    entity_Map.CreatTime = DateTime.Now;
                    entity_Map.UpdateTime = DateTime.Now;
                    entity_Map.UserName = userCode1;
                    entity_Map.PickNO = pickNO1;
                    entity_Map.MapImage = bytes1;
                    entity_Map.PickingMapImage = bytes1;
                    bll_Map.Add(entity_Map);
                }
                else
                {
                    Bitmap map = new Bitmap(this.Width, this.Height);
                    Rectangle rec = new Rectangle(Point.Empty, dataGridView1.Size);
                    this.dataGridView1.DrawToBitmap(map, rec);
                    Clipboard.SetImage(map);
                    Graphics g = Graphics.FromImage(map);
                    // 设置画布的描绘质量
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.CopyFromScreen(dataGridView1.PointToScreen(this.Location), Point.Empty, dataGridView1.Size);
                    Clipboard.SetImage(map);
                    // 保存图片
                    string nameMap = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString();
                    map.Save(Application.StartupPath + "\\PLD\\" + nameMap + ".png");

                    byte[] bytes1 = null;
                    FileStream fs1 = new FileStream(Application.StartupPath + "\\PLD\\" + nameMap + ".png", FileMode.Open);
                    bytes1 = new byte[fs1.Length];
                    fs1.Read(bytes1, 0, (int)fs1.Length);

                    entity_Map.UpdateTime = DateTime.Now;
                    entity_Map.PickingMapImage = bytes1;
                    bll_Map.Update(entity_Map);
                }
                #endregion
            }
            catch (Exception ex)
            {
                ErrorLogLoad.ErrorLogInfo(ex.ToString());
            }
        }
        #endregion

        #region
        private void checkBox1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                PickMapTimer.Enabled = true;
                timerUserName.Enabled = true;
            }
            else
            {
                PickMapTimer.Enabled = false;
                timerUserName.Enabled = false;
                indexPickNo = 0;
            }
        }
        private string pickNO1 = "";
        private string userCode1 = "";
        private int numjs = 0;
        private void PickMapTimer_Tick(object sender, EventArgs e)
        {
            //numjs = PickMapTimer.Interval;
            this.pickNO1 = this.txtPickNo.Text.Trim();
            this.userCode1 = this.comBoxName.Text.Trim();
            this.dataGridView1.Invalidate();
            this.pageControl1.Bind();
            this.btnSearch_Click(sender, e);
            if (IsLocationPostiont)
            {
                //numjs += PickMapTimer.Interval;
                //if (numjs==105000)
                //{
                this.btnLine_Click(sender, e);
                numjs = 0;
                // }

                this.SaveMap();
            }
            else
            {
                this.BtnClearLine_Click(sender, e);
            }
        }
        DataSet dsPicking = new DataSet();
        private int indexPickNo = 0;
        private void timerUserName_Tick(object sender, EventArgs e)
        {
            this.dsPicking = bll_PublicDataSet.GetDataSet("SELECT packinglistmain_no,pick_UserNO FROM dbo.T_PackingListDetails WHERE Status is null   and ProDate>='" + DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd") + "' and ProDate<='" + DateTime.Now.AddDays(2).ToString("yyyy-MM-dd") + "' GROUP BY packinglistmain_no,pick_UserNO  ");
            if (dsPicking.Tables[0].Rows.Count > 0)
            {
                if (dsPicking.Tables[0].Rows.Count == 1)
                {
                    this.txtPickNo.Text = dsPicking.Tables[0].Rows[0]["packinglistmain_no"].ToString();
                    this.comBoxName.Text = dsPicking.Tables[0].Rows[0]["pick_UserNO"].ToString();
                    this.indexPickNo = 0;
                }
                else
                {
                    if (indexPickNo == 0)
                    {
                        this.txtPickNo.Text = dsPicking.Tables[0].Rows[0]["packinglistmain_no"].ToString();
                        this.comBoxName.Text = dsPicking.Tables[0].Rows[0]["pick_UserNO"].ToString();
                        this.indexPickNo++;
                    }
                    else
                    {
                        this.txtPickNo.Text = dsPicking.Tables[0].Rows[indexPickNo]["packinglistmain_no"].ToString();
                        this.comBoxName.Text = dsPicking.Tables[0].Rows[indexPickNo]["pick_UserNO"].ToString();

                        if (indexPickNo == dsPicking.Tables[0].Rows.Count - 1)
                            this.indexPickNo = 0;
                        else
                            this.indexPickNo++;
                    }
                }
            }
        }
        #endregion
        #endregion

        #region  显示地址码
        /// <summary>
        /// 地址码信息
        /// </summary>
        private string PostionStrNo = "";
        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left && e.ColumnIndex > -1 && e.RowIndex > -1)  //点击的是鼠标右键，并且不是表头
            {
                this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;

                DataSet dsFiled = new DataSet();
                PostionStrNo = "";
                if (PD_LayoutField != "" && dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() != "")
                {
                    dsFiled = bll_PublicDataSet.GetDataSet("select PositionNO from [dbo].[PD_PostionToLayout] where Layout_NID='" + PD_LayoutNID + "' and Layout_Field='" + PD_LayoutField + "' and Stauts=0");
                    if (dsFiled != null && dsFiled.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < dsFiled.Tables[0].Rows.Count; i++)
                        {
                            PostionStrNo += dsFiled.Tables[0].Rows[i]["PositionNO"].ToString() + ";\n";
                        }
                    }
                    if (PostionStrNo != "")
                    {
                        this.contextMenuStrip1.Show(MousePosition.X + 5, MousePosition.Y + 5);
                        仓位地址码ToolStripMenuItem.Text = PostionStrNo;
                    }
                }
            }
        }
        #endregion

        #region
        private void label1_Click(object sender, EventArgs e)
        {
            //bll_PublicDataSet.ExecuteSQL(" truncate table PD_Picking ");
            //bll_PublicDataSet.ExecuteSQL(" update [dbo].[PD_PickingList] set PickQty=0,Stauts='未完成' ");
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.labeltime.Text = "时间: " + " " + Convert.ToString(DateTime.Now.ToLocalTime()) + "";
        }
        #endregion

        #region 样式
        /// <summary>
        /// 取色
        /// </summary>
        Color Color_value = System.Drawing.Color.White;
        /// <summary>
        /// 过道色块
        /// </summary>
        private void btnSet_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            Color_value = colorDialog1.Color;
            #region
            //for (int i = 0; i < dataGridView1.Rows.Count; i++)
            //{
            //    if (dataGridView1.Rows[i].Cells["txt"].Value.ToString() == "宽")
            //    {
            //        dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color_value;
            //    }
            //    else if (dataGridView1.Rows[i].Cells["txt"].Value.ToString() == "10")
            //    {
            //        dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color_value;
            //    }
            //}

            //for (int i = 0; i < dataGridView1.ColumnCount; i++)
            //{
            //    if (dataGridView1.Columns[i].HeaderText == "")
            //    {
            //        dataGridView1.Columns[i].DefaultCellStyle.BackColor = Color_value;
            //    }
            //}
            #endregion

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (i != 0 && i != dataGridView1.RowCount - 1)
                {
                    for (int j = 0; j < dataGridView1.ColumnCount; j++)
                    {
                        if (this.dataGridView1.Rows[i].Cells[j].FormattedValue.ToString() == "")
                        {
                            this.dataGridView1.Rows[i].Cells[j].Style.BackColor = Color_value;
                        }
                    }
                }
            }
        } 
        /// <summary>
        /// 布局反向
        /// </summary>
        private void checkBoxDirection_Click(object sender, EventArgs e)
        {
            if (checkBoxDirection.Checked)
            {
                #region 排序
                this.dataGridView1.Columns[0].DisplayIndex = 56;
                this.dataGridView1.Columns[1].DisplayIndex = 55;
                this.dataGridView1.Columns[2].DisplayIndex = 54;
                this.dataGridView1.Columns[3].DisplayIndex = 53;
                this.dataGridView1.Columns[4].DisplayIndex = 52;
                this.dataGridView1.Columns[5].DisplayIndex = 51;
                this.dataGridView1.Columns[6].DisplayIndex = 50;

                this.dataGridView1.Columns[7].DisplayIndex = 49;
                this.dataGridView1.Columns[8].DisplayIndex = 48;
                this.dataGridView1.Columns[9].DisplayIndex = 47;
                this.dataGridView1.Columns[10].DisplayIndex = 46;
                this.dataGridView1.Columns[11].DisplayIndex = 45;
                this.dataGridView1.Columns[12].DisplayIndex = 44;
                this.dataGridView1.Columns[13].DisplayIndex = 43;
                this.dataGridView1.Columns[14].DisplayIndex = 42;
                this.dataGridView1.Columns[15].DisplayIndex = 41;
                this.dataGridView1.Columns[16].DisplayIndex = 40;

                this.dataGridView1.Columns[17].DisplayIndex = 39;
                this.dataGridView1.Columns[18].DisplayIndex = 38;
                this.dataGridView1.Columns[19].DisplayIndex = 37;
                this.dataGridView1.Columns[20].DisplayIndex = 36;
                this.dataGridView1.Columns[21].DisplayIndex = 35;
                this.dataGridView1.Columns[22].DisplayIndex = 34;
                this.dataGridView1.Columns[23].DisplayIndex = 33;
                this.dataGridView1.Columns[24].DisplayIndex = 32;
                this.dataGridView1.Columns[25].DisplayIndex = 31;
                this.dataGridView1.Columns[26].DisplayIndex = 30;

                this.dataGridView1.Columns[27].DisplayIndex = 29;
                this.dataGridView1.Columns[28].DisplayIndex = 28;
                this.dataGridView1.Columns[29].DisplayIndex = 27;
                this.dataGridView1.Columns[30].DisplayIndex = 26;
                this.dataGridView1.Columns[31].DisplayIndex = 25;
                this.dataGridView1.Columns[32].DisplayIndex = 24;
                this.dataGridView1.Columns[33].DisplayIndex = 23;
                this.dataGridView1.Columns[34].DisplayIndex = 22;
                this.dataGridView1.Columns[35].DisplayIndex = 21;
                this.dataGridView1.Columns[36].DisplayIndex = 20;

                this.dataGridView1.Columns[37].DisplayIndex = 19;
                this.dataGridView1.Columns[38].DisplayIndex = 18;
                this.dataGridView1.Columns[39].DisplayIndex = 17;
                this.dataGridView1.Columns[40].DisplayIndex = 16;
                this.dataGridView1.Columns[41].DisplayIndex = 15;
                this.dataGridView1.Columns[42].DisplayIndex = 14;
                this.dataGridView1.Columns[43].DisplayIndex = 13;
                this.dataGridView1.Columns[44].DisplayIndex = 12;
                this.dataGridView1.Columns[45].DisplayIndex = 11;
                this.dataGridView1.Columns[46].DisplayIndex = 10;

                this.dataGridView1.Columns[47].DisplayIndex = 9;
                this.dataGridView1.Columns[48].DisplayIndex = 8;
                this.dataGridView1.Columns[49].DisplayIndex = 7;
                this.dataGridView1.Columns[50].DisplayIndex = 6;
                this.dataGridView1.Columns[51].DisplayIndex = 5;
                this.dataGridView1.Columns[52].DisplayIndex = 4;
                this.dataGridView1.Columns[53].DisplayIndex = 3;
                this.dataGridView1.Columns[54].DisplayIndex = 2;
                this.dataGridView1.Columns[55].DisplayIndex = 1;
                this.dataGridView1.Columns[56].DisplayIndex = 0;
                #endregion
            }
            else
            {
                #region 排序
                this.dataGridView1.Columns[0].DisplayIndex = 0;
                this.dataGridView1.Columns[1].DisplayIndex = 1;
                this.dataGridView1.Columns[2].DisplayIndex = 2;
                this.dataGridView1.Columns[3].DisplayIndex = 3;
                this.dataGridView1.Columns[4].DisplayIndex = 4;
                this.dataGridView1.Columns[5].DisplayIndex = 5;
                this.dataGridView1.Columns[6].DisplayIndex = 6;
                this.dataGridView1.Columns[7].DisplayIndex = 7;
                this.dataGridView1.Columns[8].DisplayIndex = 8;
                this.dataGridView1.Columns[9].DisplayIndex = 9;
                this.dataGridView1.Columns[10].DisplayIndex = 10;
                this.dataGridView1.Columns[11].DisplayIndex = 11;
                this.dataGridView1.Columns[12].DisplayIndex = 12;
                this.dataGridView1.Columns[13].DisplayIndex = 13;
                this.dataGridView1.Columns[14].DisplayIndex = 14;
                this.dataGridView1.Columns[15].DisplayIndex = 15;
                this.dataGridView1.Columns[16].DisplayIndex = 16;
                this.dataGridView1.Columns[17].DisplayIndex = 17;
                this.dataGridView1.Columns[18].DisplayIndex = 18;
                this.dataGridView1.Columns[19].DisplayIndex = 19;
                this.dataGridView1.Columns[20].DisplayIndex = 20;
                this.dataGridView1.Columns[21].DisplayIndex = 21;
                this.dataGridView1.Columns[22].DisplayIndex = 22;
                this.dataGridView1.Columns[23].DisplayIndex = 23;
                this.dataGridView1.Columns[24].DisplayIndex = 24;
                this.dataGridView1.Columns[25].DisplayIndex = 25;
                this.dataGridView1.Columns[26].DisplayIndex = 26;
                this.dataGridView1.Columns[27].DisplayIndex = 27;
                this.dataGridView1.Columns[28].DisplayIndex = 28;
                this.dataGridView1.Columns[29].DisplayIndex = 29;
                this.dataGridView1.Columns[30].DisplayIndex = 30;
                this.dataGridView1.Columns[31].DisplayIndex = 31;
                this.dataGridView1.Columns[32].DisplayIndex = 32;
                this.dataGridView1.Columns[33].DisplayIndex = 33;
                this.dataGridView1.Columns[34].DisplayIndex = 34;
                this.dataGridView1.Columns[35].DisplayIndex = 35;
                this.dataGridView1.Columns[36].DisplayIndex = 36;
                this.dataGridView1.Columns[37].DisplayIndex = 37;
                this.dataGridView1.Columns[38].DisplayIndex = 38;
                this.dataGridView1.Columns[39].DisplayIndex = 39;
                this.dataGridView1.Columns[40].DisplayIndex = 40;
                this.dataGridView1.Columns[41].DisplayIndex = 41;
                this.dataGridView1.Columns[42].DisplayIndex = 42;
                this.dataGridView1.Columns[43].DisplayIndex = 43;
                this.dataGridView1.Columns[44].DisplayIndex = 44;
                this.dataGridView1.Columns[45].DisplayIndex = 45;
                this.dataGridView1.Columns[46].DisplayIndex = 46;
                this.dataGridView1.Columns[47].DisplayIndex = 47;
                this.dataGridView1.Columns[48].DisplayIndex = 48;
                this.dataGridView1.Columns[49].DisplayIndex = 49;
                this.dataGridView1.Columns[50].DisplayIndex = 50;
                this.dataGridView1.Columns[51].DisplayIndex = 51;
                this.dataGridView1.Columns[52].DisplayIndex = 52;
                this.dataGridView1.Columns[53].DisplayIndex = 53;
                this.dataGridView1.Columns[54].DisplayIndex = 54;
                this.dataGridView1.Columns[55].DisplayIndex = 55;
                this.dataGridView1.Columns[56].DisplayIndex = 56;
                #endregion
            }
        }
        #endregion
    }
}
